home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / toggleMaterialMapping.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.0 KB  |  128 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // 
  18. // Toggle the ignore while rendering flag on = 1 or off = 0 for all the shaders 
  19. // attached to the selected objects. 
  20. //
  21. // The only problem with this script is that .transparency defaults
  22. // to a non-opaque value !
  23. // 
  24. global proc toggleMaterialMapping(int $state) 
  25.     string $selList[] = `selectedNodes -do`;
  26.     string $currentObj; 
  27.     for ( $currentObj in $selList ) 
  28.     { 
  29.         //print("Handle object " + $currentObj + "\n");
  30.  
  31.         string $shdGrpList[] = `listSets -type 1 -ets -object $currentObj`; 
  32.         string $currentSG; 
  33.         //print ($shdGrpList);
  34.         for ($currentSG in $shdGrpList ) 
  35.         { 
  36.             string $srfShdrs[] = `listConnections -d off 
  37.                 ($currentSG + ".surfaceShader")`; 
  38.  
  39.             if (size($srfShdrs) > 0)
  40.             {
  41.                 string $killShader;
  42.                 $killShader = $srfShdrs[0];
  43.  
  44.                 //print("// Ignore texture on shader " + $killShader + 
  45.                 //      "( shading group " + $currentSG + ")\n");
  46.  
  47.                 //
  48.                 // To create the initial ignore attribute, set
  49.                 // just one of the texturable attributes to "ignore".
  50.                 // "color" is as good as any attribute.
  51.                 //
  52.                 // Check for a layered shader or layered texture. If it's
  53.                 // a layered shader, then you want to turn off a each of it's
  54.                 // inputs.
  55.                 // 
  56.                 string $shaderType = `nodeType $killShader`;
  57.                 if ($shaderType == "layeredShader")
  58.                 {
  59.                     string $layeredShaders[] = 
  60.                         `listConnections -d off ($killShader+".inputs")`;
  61.                     if (size($layeredShaders))
  62.                     {
  63.                         int $count = 0;
  64.                         for ($s in $layeredShaders)
  65.                         {
  66.                             //print("Change layered shader texture input " + $s + "\n");
  67.                             shadingConnection -e -cs $state 
  68.                                 ($killShader + ".inputs["+$count+"].color"); 
  69.                             $count++;
  70.                         }
  71.                     }
  72.                 }
  73.                 else
  74.                 {
  75.                     //print("Touch shader input " + $killShader + "\n");
  76.                     shadingConnection -e -cs $state ($killShader + ".color"); 
  77.  
  78.                     string $attrs[] = `listAttr -ud $killShader`;
  79.                     int $i;
  80.                     int $ignoreExists = 0;
  81.                     for ($i =0; $i < size($attrs); $i++)
  82.                     {
  83.                         if (match("ignored", $attrs[$i]) == "ignored")
  84.                         {
  85.                             $ignoreExists = 1;
  86.                             $i = size($attrs)+10;
  87.                         }
  88.                     }
  89.                     
  90.                     if ($ignoreExists == 0)
  91.                     {
  92.                         //print("Add ignore attribute\n");
  93.                         addAttr -multi -at long -sn "isc" -bt "IGSC" 
  94.                             -ln "ignoredShadingConnections" $killShader;
  95.                     }
  96.                     else
  97.                     {
  98.                         //print("Ignore attribute already exists\n");
  99.                     }
  100.                     
  101.                     // Just hard code enough entries to make sure we
  102.                     // toggle on/off every mappable attribute.
  103.                     //
  104.                     //$ignoreSize = 
  105.                     //`getAttr -s ($killShader + ".ignoredShadingConnections")`;
  106.                     $ignoreSize = 3;
  107.                     //print ("Kill shader " + $killShader + ". Ignore size = " 
  108.                     // + $ignoreSize + "\n");
  109.                     for ($i=0; $i < $ignoreSize; $i++)
  110.                     {
  111.                         //print ($killShader + ".ignoredShadingConnections[" + $i + "]");
  112.                         //print (" set to state " + $state + "\n");
  113.                         if ($state)
  114.                             setAttr ($killShader + 
  115.                                      ".ignoredShadingConnections[" + $i + "]") 
  116.                             0;
  117.                         else
  118.                             setAttr ($killShader + 
  119.                                      ".ignoredShadingConnections[" + $i + "]") 
  120.                             1064744371;
  121.                     }
  122.                 }
  123.             }
  124.         }
  125.     } 
  126.